//package com.woniuxy.commons.consumer;
//
//import com.woniuxy.commons.util.AlipayUtil;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//
//@Component
//@RabbitListener(queues = "order_check_queue")
//public class CheckOrderConsumer {
//    @Autowired
//    private AlipayUtil alipayUtil;
//    @Autowired
//    private GoodsOrderInfoMapper goodsOrderInfoMapper;
//    @Autowired
//    private GoodsOrderItemMapper goodsOrderItemMapper;
//    @Autowired
//    private GoodsMapper goodsMapper;
//
//    @RabbitHandler
//    public void handler(String orderNum) throws Exception {
//        PayInfoDto payInfoDto = alipayUtil.queryPayState(orderNum);
//        GoodsOrderInfo orderInfo = goodsOrderInfoMapper.selectById(orderNum);
//        if (payInfoDto.getPayState().equals("TRADE_SUCCESS")) {
//            if (orderInfo.getOrderState() == StateUtil.ORDER_INFO_NORMAL) {
//                QueryWrapper<GoodsOrderItem> w = new QueryWrapper<>();
//                w.eq("order_info_id", orderInfo.getId());
//                GoodsOrderItem goodsOrderItem = goodsOrderItemMapper.selectOne(w);
//                Goods goods = goodsMapper.selectById(goodsOrderItem.getGoodsId());
//                //修改冻结量
//                goods.setGoodsFreeze(goods.getGoodsFreeze() - goodsOrderItem.getGoodsCont());
//                //修改订单状态
//                orderInfo.setOrderState(StateUtil.ORDER_INFO_COMPLETED);
//                //支付时间
//                LocalDateTime localDateTime = LocalDateTime.parse(payInfoDto.getPayDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//                orderInfo.setPayTime(localDateTime);
//                goodsOrderInfoMapper.updateById(orderInfo);
//                goodsMapper.updateById(goods);
//            }
//        } else {//未支付
//            orderInfo.setOrderState(StateUtil.ORDER_INFO_CANCEL);
//            goodsOrderInfoMapper.updateById(orderInfo);
//        }
//    }
//}
